import configparser
import os

from pygame import image, sprite, mask

"""
我方飞机弹药实体
"""
def resder_config():
    conf = configparser.ConfigParser()
    curpath = os.path.dirname(os.path.realpath(__file__))
    path = os.path.join(curpath, '../config.ini')
    conf.read(path, encoding="utf-8")
    client_config = conf["client"]
    gameplay_config = conf["gameplay"]
    return client_config, gameplay_config


_, gameplay_config = resder_config()


class Bullet1(sprite.Sprite):
    def __init__(self, position):
        super().__init__()
        self.image = image.load("./images/bullet.png")
        self.rect = self.image.get_rect()
        self.rect.left, self.rect.top = position
        self.speed = int(gameplay_config["bullet_speed"])
        self.active = True
        self.mask = mask.from_surface(self.image)

    def move(self):
        self.rect.top -= self.speed
        if self.rect.top < 0:
            self.active = False

    def reset(self, position):
        self.rect.left, self.rect.top = position
        self.active = True


# 强化
class Bullet2(sprite.Sprite):
    def __init__(self, position):
        super().__init__()
        self.image = image.load("./images/s_bullet.png")
        self.rect = self.image.get_rect()
        self.rect.left, self.rect.top = position
        self.speed = int(gameplay_config["s_bullet_speed"])
        self.active = False
        self.mask = mask.from_surface(self.image)

    def move(self):
        self.rect.top -= self.speed
        if self.rect.top < 0:
            self.active = False

    def reset(self, position):
        self.rect.left, self.rect.top = position
        self.active = True
